home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstDestroy.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  2.0 KB  |  98 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     88.11.17.20.52.15;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.5
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.36.
  23. @
  24. text
  25. @/*-
  26.  * LstDestroy.c --
  27.  *    Nuke a list and all its resources
  28.  *
  29.  * Copyright (c) 1988 by University of California Regents
  30.  *
  31.  * Permission to use, copy, modify, and distribute this
  32.  * software and its documentation for any purpose and without
  33.  * fee is hereby granted, provided that the above copyright
  34.  * notice appears in all copies.  Neither the University of California nor
  35.  * Adam de Boor makes any representations about the suitability of this
  36.  * software for any purpose.  It is provided "as is" without
  37.  * express or implied warranty.
  38.  */
  39. #ifndef lint
  40. static char *rcsid =
  41. "$Id: lstDestroy.c,v 1.5 88/11/17 20:52:15 adam Exp $ SPRITE (Berkeley)";
  42. #endif lint
  43.  
  44. #include    "lstInt.h"
  45.  
  46. /*-
  47.  *-----------------------------------------------------------------------
  48.  * Lst_Destroy --
  49.  *    Destroy a list and free all its resources. If the freeProc is
  50.  *    given, it is called with the datum from each node in turn before
  51.  *    the node is freed.
  52.  *
  53.  * Results:
  54.  *    None.
  55.  *
  56.  * Side Effects:
  57.  *    The given list is freed in its entirety.
  58.  *
  59.  *-----------------------------------------------------------------------
  60.  */
  61. void
  62. Lst_Destroy (l, freeProc)
  63.     Lst                  l;
  64.     register void    (*freeProc)();
  65. {
  66.     register ListNode    ln;
  67.     register ListNode    tln = NilListNode;
  68.     register List     list = (List)l;
  69.     
  70.     if (l == NILLST || ! l) {
  71.     /*
  72.      * Note the check for l == (Lst)0 to catch uninitialized static Lst's.
  73.      * Gross, but useful.
  74.      */
  75.     return;
  76.     }
  77.     
  78.     if (freeProc) {
  79.     for (ln = list->firstPtr;
  80.          ln != NilListNode && tln != list->firstPtr;
  81.          ln = tln) {
  82.          tln = ln->nextPtr;
  83.          (*freeProc) (ln->datum);
  84.          free ((Address)ln);
  85.     }
  86.     } else {
  87.     for (ln = list->firstPtr;
  88.          ln != NilListNode && tln != list->firstPtr;
  89.          ln = tln) {
  90.          tln = ln->nextPtr;
  91.          free ((Address)ln);
  92.     }
  93.     }
  94.     
  95.     free ((Address)l);
  96. }
  97. @
  98.